package com.maegul.web.components;

import java.io.Serializable;
import java.text.NumberFormat;
import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

import com.maegul.data.entities.CartItem;
import com.maegul.web.MaegulSession;

public class ShoppingCartPanel extends Panel {

	private static final long serialVersionUID = 1L;

	public ShoppingCartPanel(String id) {
		super(id);

		add(new Label("numitems", new Model<Integer>() {

			private static final long serialVersionUID = 1L;

			@Override
			public Integer getObject() {
				return MaegulSession.get().getCart().size();
			}

		}));

		add(new Label("total", new Model<Serializable>() {

			private static final long serialVersionUID = 1L;

			@Override
			public Serializable getObject() {
				NumberFormat nf = NumberFormat.getCurrencyInstance();
				List<CartItem> cart = MaegulSession.get().getCart();
				double total = 0;

				for (CartItem item : cart) {
					System.out.println(cart.size());
					System.out.println(item);
					System.out.println(cart.get(0));
					total += item.getMediaItemBean().getPrice();
				}

				return nf.format(total);
			}
		}));
	}

}
